package com.ysqcould.Community.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ysqcould.Community.domain.SocUsefulActivity;
import com.ysqcould.Community.mapper.SocUsefulActivityMapper;
import com.ysqcould.Community.service.ISocUsefulActivityService;
import com.ysqcould.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 活动人员信息Service业务层处理
 * 
 * @author jcd
 * @date 2022-09-20
 */
@Service
public class SocUsefulActivityServiceImpl implements ISocUsefulActivityService 
{
    @Autowired
    private SocUsefulActivityMapper socUsefulActivityMapper;

    /**
     * 查询活动人员信息
     * 
     * @param id 活动人员信息主键
     * @return 活动人员信息
     */
    @Override
    public SocUsefulActivity selectSocUsefulActivityById(Long id)
    {
        return socUsefulActivityMapper.selectSocUsefulActivityById(id);
    }

    /**
     * 查询活动人员信息列表
     * 
     * @param socUsefulActivity 活动人员信息
     * @return 活动人员信息
     */
    @Override
    public List<SocUsefulActivity> selectSocUsefulActivityList(SocUsefulActivity socUsefulActivity)
    {
         List<String> valList=new ArrayList<>();
        final List<SocUsefulActivity> list = socUsefulActivityMapper.selectSocUsefulActivityList(socUsefulActivity);

        list.forEach(p->{
            List listA=new ArrayList<>();
            JSONArray objects = JSONArray.parseArray(p.getContent());
            for (int i = 0; i <objects.size() ; i++) {
                Map<String,Object> map=new LinkedHashMap<>();
                JSONObject jsonObject = objects.getJSONObject(i);
                String value = jsonObject.getString("value");
                map.put("name"+i,value);
                listA.add(map);
            }
            String s = JSON.toJSON(listA).toString();
            String replace = s.replace("},{", ",");
            System.out.println(replace);
            p.setList(replace);
        });
        return list;
    }

    /**
     * 新增活动人员信息
     * 
     * @param socUsefulActivity 活动人员信息
     * @return 结果
     */
    @Override
    public int insertSocUsefulActivity(SocUsefulActivity socUsefulActivity)
    {
        socUsefulActivity.setCreateTime(DateUtils.getNowDate());
        return socUsefulActivityMapper.insertSocUsefulActivity(socUsefulActivity);
    }

    /**
     * 修改活动人员信息
     * 
     * @param socUsefulActivity 活动人员信息
     * @return 结果
     */
    @Override
    public int updateSocUsefulActivity(SocUsefulActivity socUsefulActivity)
    {
        socUsefulActivity.setUpdateTime(DateUtils.getNowDate());
        return socUsefulActivityMapper.updateSocUsefulActivity(socUsefulActivity);
    }

    /**
     * 批量删除活动人员信息
     * 
     * @param ids 需要删除的活动人员信息主键
     * @return 结果
     */
    @Override
    public int deleteSocUsefulActivityByIds(Long[] ids)
    {
        return socUsefulActivityMapper.deleteSocUsefulActivityByIds(ids);
    }

    /**
     * 删除活动人员信息信息
     * 
     * @param id 活动人员信息主键
     * @return 结果
     */
    @Override
    public int deleteSocUsefulActivityById(Long id)
    {
        return socUsefulActivityMapper.deleteSocUsefulActivityById(id);
    }
}
